package com.sportschain.app.shop;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sportschain.app.R;
import com.sportschain.app.core.base.BasePagerFragment;
import com.sportschain.app.shop.activity.CommodityDetailActivity;
import com.sportschain.app.shop.adapter.RecommendCommodityAdapter;
import com.sportschain.app.shop.bean.RecommendCommodityBean;
import com.sportschain.app.shop.widget.ShopHeaderViewWrapper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ShopFragment extends BasePagerFragment {

    @BindView(R.id.recommend_commodity_rv)
    RecyclerView mRecommendCommodityRv;

    private ShopHeaderViewWrapper mHeaderViewWrapper;
    private RecommendCommodityAdapter mAdapter;

    public static ShopFragment newInstance() {

        Bundle args = new Bundle();

        ShopFragment fragment = new ShopFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_shop;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mHeaderViewWrapper = new ShopHeaderViewWrapper(mActivity);
        mAdapter = new RecommendCommodityAdapter();
        mAdapter.bindToRecyclerView(mRecommendCommodityRv);
        mAdapter.addHeaderView(mHeaderViewWrapper.getView());
        mAdapter.setEmptyView(R.layout.empty_view_layout);
    }

    @Override
    protected void initData() {
        List<RecommendCommodityBean> data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            data.add(new RecommendCommodityBean());
        }
        mAdapter.setNewData(data);
    }

    @Override
    protected void initListener() {
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                startActivity(CommodityDetailActivity.class);
            }
        });
    }
}
